import pymysql
cos=0
conn=0
try:
    conn=pymysql.connect(host="192.168.88.128", port=3306,user="root" , passwd="123456",
                       database="test_db", charset="utf8")

    cos=conn.cursor()
    sql="select * fro t_book"
    cos.execute(sql)
    print(cos.fetchone())
except Exception as k:
    print('发生异常',k)
    raise k
finally:
    if cos!=0:
        cos.close()
    if conn!=0:
        conn.close()